package com.gouqi.search.datasource;

import com.gouqi.search.model.enums.SearchTypeEnum;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Component
public class DataRegistry {

    @Resource
    private PostSource postSource;

    @Resource
    private UserSource userSource;

    @Resource
    private PictureSource pictureSource;

    private Map<String, DataSource<T>> typeDataSourceMap;

    @PostConstruct
    public void init() {
        typeDataSourceMap = new HashMap() {
            {
                put(SearchTypeEnum.POST.getValue(), postSource);
                put(SearchTypeEnum.USER.getValue(), userSource);
                put(SearchTypeEnum.PICTURE.getValue(), pictureSource);
            }
        };
    }

    public DataSource<T> getDataSourceByType(String type) {
        if (typeDataSourceMap == null) {
            return null;
        }
        return typeDataSourceMap.get(type);
    }
}